<{include file="Public/top.html" }>
<style>
    #statusTip{
        color: red;
        font-weight:600;}
</style>
</head>
<body >
<div id="warpper">
    <form action="<{U(<{u($smarty.const.ACTION_NAME)}>)}>" method="post" class="ui-form" id="form">
    <div class="content">
        <{include file= "Schedule/nav.html"}>
        <div class="topic"><{if $obj.aid}>修改<{else}>增加<{/if}>推文排期</div>
        <div class="form-box border0 border-box">
            <input type="hidden" name="aid" value="<{$obj.aid}>" />
                <div class="ui-form-item inline-block" style="vertical-align:top;">
                    <dl>
                        <label class="ui-label">发布日期</label>
                        <input required id="publishDate" name="publishDate" value="<{$obj.publishDate}>" class="ui-select" type="text" />
                    </dl>
                    <dl>
                        <label class="ui-label">标题</label>
                        <input type="text" class="ui-text" id="title" name="title" value="<{$obj.title}>" required/>
                    </dl>


                    <dl>
                        <label class="ui-label">位置</label>
                        <select name="position" >
                            <{html_options options=$placeKv selected=$obj.position}>
                        </select>
                    </dl>
                    <dl>
                        <label class="ui-label">类型</label>
                        <select name="businessType" id="businessType">
                            <{html_options options=$businessTypeKv selected=$obj.businessType}>
                        </select>
                    </dl>

                    <dl class="fee" <{if $needFee eq 0  }> style="display:none"  <{/if}> >
                        <label class="ui-label">费用</label>
                        <input type="text" value="<{$obj.fee}>" class="ui-text" id="fee" name="fee" />
                    </dl>

                    <dl class="fee" <{if $needFee eq 0  }> style="display:none"  <{/if}>>
                        <label class="ui-label">是否需要发票</label>
                        <input type="radio" value="0" name="needInvoice" <{if $obj.needInvoice eq 0}>checked<{/if}> >不需要
                        <input type="radio" value="1" name="needInvoice" <{if $obj.needInvoice eq 1}>checked<{/if}> >需要
                    </dl>


                    <dl>
                        <label class="ui-label">内容对接</label>
                        <select name="writerName" class="ui-select">
                            <{foreach from=$userList item=uname}>
                            <option value="<{$uname}>" <{if $uname eq $obj.writerName}> selected <{/if}>><{$uname}></option>
                            <{/foreach}>
                        </select>
                    </dl>

                    <div class="reply_box">
                        <label class="ui-label">备注说明</label>
                        <textarea  name="mem" style="width:300px;height:100px;"><{$obj.mem}></textarea>
                    </div>

                    <dl>
                        <label class="ui-label">推文状态</label>
                        <select name="status" class="ui-select">
                            <{html_options options=$statusKv selected=$obj.status}>
                        </select>
                    </dl>

                    <dl>
                        <label class="ui-label">是否绑定活动</label>
                        <select id="eventBind" name="eventBind" class="ui-select">
                            <option value="0">不关联活动</option>
                            <option value="1">新建活动</option>
                            <option value="2" <{if $obj.bindEvent gt 0}> selected <{/if}> >关联现有活动</option>
                        </select>
                    </dl>
        </div>
    </div>

    </div>


        <div class="content" id="eventContainer" style="display:<{if $obj.bindEvent eq 0}> none <{/if}>">
            <div class="topic">活动</div>
            <div class="form-box border0 border-box">

                <div class="ui-form-item inline-block" style="vertical-align:top;">

                    <dl id="existEvent">
                        <label class="ui-label">现有活动</label>
                        <select name="existEventId" id="existEventId" class="ui-select">
                            <option value="0">请选择活动</option>
                            <{html_options options=$eventKv selected=$evt.eid}>
                        </select>
                    </dl>

                    <dl id="newEvent">
                        <label class="ui-label">活动标题</label>
                        <input type="text" class="ui-text" id="event_title"  name="event_title" value="<{$evt.title}>" />
                    </dl>

                    <dl>
                        <label class="ui-label">活动日期</label>
                        <input type="text" id="eventDate" name="eventDate" value="<{$evt.eventDate}>" class="ui-select" type="text" />
                    </dl>

                    <dl>
                        <label class="ui-label">活动对接</label>
                        <select name="operatorName" id="operatorName" class="ui-select">
                            <{foreach from=$userList item=uname}>
                            <option value="<{$uname}>" <{if $uname eq $evt.operatorName}> selected <{/if}>><{$uname}></option>
                            <{/foreach}>
                        </select>
                    </dl>

                    <dl>
                        <label class="ui-label">报名方式</label>
                        <select name="signType" id="signType" class="ui-select">
                            <{html_options options=$signTypeKv selected=$evt.signType}>
                        </select>
                    </dl>

                    <dl class="sign" <{if $evt.signType eq 0}>style="display:none" <{/if}>>
                        <label class="ui-label">名额</label>
                        <input type="text" class="ui-text" id="quota"  name="quota" value="<{$evt.quota}>" />
                    </dl>

                    <dl class="sign" <{if $evt.signType eq 0}>style="display:none" <{/if}>>
                        <label class="ui-label">名单确定时间</label>
                        <input id="listSureTime" name="listSureTime"  value='<{$evt.listSureTime|date_format:"%Y-%m-%d %H:%M"}>' class="ui-select" type="text" />
                    </dl>

                    <div class="reply_box">
                        <label class="ui-label">活动说明</label>
                        <textarea id="event_mem"   name="event_mem" style="width:300px;height:100px;"><{$evt.mem}></textarea>
                    </div>
                    <dl>
                        <label class="ui-label">活动状态</label>
                        <select name="event_status" id="event_status" class="ui-select">
                            <{html_options options=$statusKv selected=$evt.status}>
                        </select>
                    </dl>
                    <dl>
                        <label class="ui-label"></label>
                        <div id="statusTip" style="display: none">活动取消，今天(含)以后与之相关的推文也将一并取消</div>
                    </dl>

                </div>
            </div>
        </div>

        <div class="integral_btn-group">
            <input type="submit" value="提交" class="ui-button"/>
        </div>
    </form>
</div>

<{include file="Public/foot.html" }>

<script>

    datePickter('publishDate');
    datePickter('eventDate');
    datePickter('listSureTime');

    $(document).ready(function(){
        $('#businessType').on('change',function(){
            var v=parseInt($(this).val());
            if(v==1 || v==3){//付费
                $('.fee').show();
            }else{
                $('.fee').hide();
            }
        })
        $('#signType').on('change',function(){
            var v=$(this).val();
            if(v=='0'){
                $('.sign').hide();
            }else{
                $('.sign').show();
            }
        })

        $('#event_status').on('change',function(){
            var v=$(this).val();
            if(v=='<{$statusCandel}>'){
                $('#statusTip').css({'display':'inline-block'});
            }else{
                $('#statusTip').hide();
            }
        })

        $('#eventBind').on('change',function(){
            var v=parseInt($(this).val());
            if(v==0){
                $('#eventContainer').hide();
            }else{
                $('#eventContainer').show();
                if(v==1){
                    $('#existEvent').hide();
                    $('#newEvent').show();
                }else{
                    $('#existEvent').show();
                    $('#newEvent').hide();
                }
            }
        })
        $('#existEventId').on('change',function(){
            var v=$('#existEventId').val();
            $.post("<{u('getEventDetail')}>",{eid:v},function(res){
                if(res.status!=0){
                    layer.msg(res.msg);
                }
                $('#eventDate').val(res.data.eventDate);
                $('#listSureTime').val(res.data.listSureTime);
                $('#event_mem').val(res.data.mem);
                $('#quota').val(res.data.quota);
                $('#event_title').val(res.data.title);

                setSelect('#operatorName',res.data.operatorName);
                setSelect('#signType',res.data.signType);
                if(res.data.signType == 0){
                        $('.sign').hide();
                }else{
                        $('.sign').show();
                }
                setSelect('#event_status',res.data.status);
            })

        })
    });

    function setSelect($id,$val){
        $($id).find('option').each(function(i,m){
            var $m=$(m)
            if($m.val()==$val){
                $m.attr('selected','selected');
            }
        })
    }


    $("form").submit(function () {
        if($('#event_status').val()=='<{$statusCandel}>' && !window.confirm("确定取消该活动吗？\n今天(含)以后与之相关的推文也将一并取消\n取消后不可恢复")) {
            return false;
        }
        layer.msg("正在提交数据...",{time:999});
        $.post("<{U(<{u($smarty.const.ACTION_NAME)}>)}>",$(this).serialize(), function(data){
            layer.closeAll();
            if(data.status==0){
                layer.msg(data.msg,{time: 3000,},function(){location.href="<{U('scheduleList')}>";});
            }else{
                layer.msg(data.msg);
                if(typeof data.eid !='undefined'){
                    $('#existEvent').show();
                    $('#newEvent').hide();
                    $('#existEventId').prepend("<option value='"+data.eid+"'>"+data.eventTitle+"</option>");
                }

            }
        }, 'json');
        return false;
    });
</script>